package dell.yangzhou;
//特点：代理类、被代理类在编译期间就被确定下来了
public class ProxyCloth01 {
    public static void main(String[] args) {
//创建被代理类对象
        NikeClothFactory nikeClothFactory=new NikeClothFactory();
        //创建代理类对象
        ProxyClothFactory proxyClothFactory=new ProxyClothFactory(nikeClothFactory);
        proxyClothFactory.produceCloth();
        //通过代理类对象调用被代理类封装的方法
    }
}
//静态代理举例
interface ClothFactory{
    void produceCloth();
}
//代理类
class ProxyClothFactory implements ClothFactory{
private ClothFactory factory;//用被代理类对象进行实例化
//提供当前类的构造器
    public ProxyClothFactory(ClothFactory factory){
       this.factory=factory;
    }
    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一些准备工作");
        factory.produceCloth();//被代理类对象开始执行方法
        System.out.println("代理工厂做一些后续的收尾工作");
    }
}
//被代理类
class NikeClothFactory implements ClothFactory{
    @Override
    public void produceCloth() {
        System.out.println("Nike工厂生产一批运动服");
    }
}